<?php


namespace App\Http\Controllers\App;


use App\Http\Controllers\Controller;
use App\Models\Version;

class VersionController extends Controller
{
    public function version()
    {
        $this->validate(request(), [
            'type' => 'required',
            'number' => 'required',
        ], [
            'type.required' => '版本类型不正确',
            'number.required' => '版本号不正确',
        ]);

        $number = request('number');
        $type = request('type');

        $version = Version::where('type', $type)->first();

        if ($version->number > $number) {
            return ['update' => 1, 'url' => $version->url];
        } else {
            return ['update' => 0, 'url' => $version->url];
        }
    }

}